package com.example.study.commen.servletlistener;

//import com.example.study.plus.mybatis_plus.entity.User;
//import com.example.study.plus.mybatis_plus.service.impl.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * 拦截器的缓存向应用。
 */
//@Component
public class MyServletContextListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // 先获取到application上下文
        ApplicationContext applicationContext = event.getApplicationContext();
        // 获取对应的service
//        UserServiceImpl userService = applicationContext.getBean(UserServiceImpl.class);
//        List<String> userList = userService.getUserList();
        // 获取application域对象，将查到的信息放到application域中
//        ServletContext servletContext = applicationContext.getBean(ServletContext.class);
//        servletContext.setAttribute("userList",userList);
    }
}
